'use strict';

var mongoose = require('mongoose'),
  debug = require('debug'),
  log = debug('yozh:config:log'),
  error = debug('yozh:config:error'),
  verbose = debug('yozh:config:verbose'),
  config = require('./config');

// set Promise provider to bluebird
// mongoose.Promise = require('bluebird');
// var Promise = require("bluebird");
// Promise.promisifyAll(mongoose);
// native promises
mongoose.Promise = global.Promise;

require('../modules/base/base.model.js');
require('../modules/user/user.model.js');
require('../modules/article/article.model.js');
require('../modules/log/log.model.js');
require('../modules/menu/menu.model.js');
require('../modules/part/part.model.js');
require('../modules/role/role.model.js');
require('../modules/topic/topic.model.js');
require('../modules/operator/operator.model.js');
require('../modules/relation/relation.model.js');
require('../modules/wechat/robrule.model.js');

mongoose.connect(config.db);
var dbConn = mongoose.connection;

dbConn.on('error', console.error.bind(console, 'connection error: '));
dbConn.once('open', function(){
  log('open mongodb connection!');
});

exports.baseModel = mongoose.model('Base');
exports.userModel = mongoose.model('User');
exports.articleModel = mongoose.model('Article');
exports.logModel = mongoose.model('Log');
exports.menuModel = mongoose.model('Menu');
exports.partModel = mongoose.model('Part');
exports.roleModel = mongoose.model('Role');
exports.topicModel = mongoose.model('Topic');
exports.operatorModel = mongoose.model('Operator');
exports.relationModel = mongoose.model('Relation');
exports.robruleModel = mongoose.model('Robrule');
